<?php

class Model_Lookup extends Model {

    function __construct() {
        
    }

    /* 列出全部名稱
     * $type string 分類名稱：agegroup,body_skin,body,brand,event,face_skin,,hair,marital_status,member,product_layout_category, product_reports_well,product,question,profession,interest,help,help_sub,vote_option,fg_vote_option_type
     * $page 當前頁數
     * $size 每頁記錄數
     */

    function h_get_lookup($h_param = array()) {
        $prama = array();
        $prama_key_0 = array('id', 'topid', 'member_type', 'is_mobile');
        if ($prama_key_0) {
            foreach ($prama_key_0 as $value) {
                $prama[$value] = (!empty($h_param[$value])) ? $h_param[$value] : 0;
            }
        }
        $prama['type'] = (!empty($h_param['type'])) ? $h_param['type'] : "";
        $prama['size'] = (!empty($h_param['size'])) ? $h_param['size'] : 999;
        $prama['page'] = (!empty($h_param['page'])) ? $h_param['page'] : 1;

        return $this->getLookup($prama['type'], $prama['id'], $prama['page'], $prama['size'], $prama['topid'], $prama['member_type'], $prama['is_mobile']);
    }

    /* 列出全部名稱
     * $type string 分類名稱：agegroup,body_skin,body,brand,event,face_skin,,hair,marital_status,member,product_layout_category, product_reports_well,product,question,profession,interest,help,help_sub,vote_option,fg_vote_option_type
     * $page 當前頁數
     * $size 每頁記錄數
     */

    function getLookup($type = '', $id = 0, $page = 1, $size = 999, $topid = 0, $member_type = 0, $is_mobile = 0, $is_fg = 0) {
        if (!$type)
            return false;
        $where = "status=1";
        if (intval($id))
            $where .=" and id=" . intval($id);
        $param = array();
        $param['field'] = "id,name,cname,status,lastmodify";
        $param['where'] = $where;
        $param['order'] = "id asc"; //"id asc"
        $param['group'] = "";
        $param['limit'] = "";
        $param['pagesize'] = $size;
        $param['page'] = $page;
        $param['join'] = "";
        $param['on'] = "";

        $data = array();
        switch ($type) {
            case 'agegroup':
                $data = db_query_hash('agegroup_type', $param);
                break;
            case 'fg_vote_option_type':
                $param['field'] = "id,fg_cname,cname,status,lastmodify";
                $data = db_query_hash('fg_vote_option_type', $param);
                break;
            case 'body_skin':
                $data = db_query_hash('body_skin_type', $param);
                break;
            case 'body':
                $data = db_query_hash('body_type', $param);
                break;
            case 'brand':
                $param['order'] = "LTRIM(name) asc "; //"id asc"
                $data = db_query_hash('brand', $param);
                break;
            case'event':
                $data = db_query_hash('event_type', $param);
                break;
            case'face_skin':
                $data = db_query_hash('face_skin_type', $param);
                break;
            case'hair':
                $data = db_query_hash('hair_type', $param);
                break;
            case'marital_status':
                $data = db_query_hash('marital_status_type', $param);
                break;
            case'member':
                $data = db_query_hash('member_type', $param);
                break;

            case'product_layout_category':
                $param['field'] = "id,name,cname,m_icon_image2,topid,products_expert_num,products_trialist_num,products_fg_num,status,lastmodify,sequence";
                if (!$topid) {
                    $param['where'] = $where . " and topid = 0";
                } elseif ($member_type == 5 && $topid) {
                    $param['where'] = $where . " and products_expert_num>0 and topid = " . $topid;
                } elseif ($member_type == 1 && $topid) {
                    $param['where'] = $where . " and products_trialist_num>0 and topid = " . $topid;
                } elseif ($is_fg && $topid) {
                    $param['where'] = $where . " and products_fg_num>0 and topid = " . $topid;
                } elseif ($is_mobile && $topid) {
                    $param['where'] = $where . " and (products_expert_num+products_trialist_num)>0 and topid = " . $topid;
                } elseif ($topid) {
                    $param['where'] = $where . " and topid = " . $topid;
                }
                $param['order'] = "sequence asc,id asc"; //"id asc"
                $data = db_query_hash('product_layout_category', $param);
                break;
            /*
              case'product_layout_category':
              $param['field'] = "id,name,cname";
              //$param['where'] = $where." and topid = 0";
              $data = db_query_hash('product_type',$param);
              break;
             */
            case'product_reports_well':
                $data = db_query_hash('product_reports_well_type', $param);
                break;
            case'product':
                $data = db_query_hash('product_type', $param);
                break;
            case'question':
                $data = db_query_hash('question_type', $param);
                break;
            case'profession':
                $data = db_query_hash('profession_type', $param);
                break;
            case'vote_option':
                $data = db_query_hash('product_vote_option', $param);
                break;
            case 'interest':
                $data = db_query_hash('interest_type', $param);
                break;
            case'product_layout_category_all':
                $param['field'] = "id,name,cname,m_icon_image2,topid,products_expert_num,products_trialist_num,status,lastmodify,sequence";
                $param['where'] = $where . " ";
                $param['order'] = "sequence asc,id asc"; //"id asc"
                $data = db_query_hash('product_layout_category', $param);
                break;
            case 'help':
                $param['field'] = "id,name,cname,topid";
                $param['where'] = $where . " and topid = 0";
                $data = db_query_hash('help_type', $param);
                break;
            case 'help_sub':
                $param['field'] = "id,name,cname,topid";
                $param['where'] = $where . " and topid=" . intval($topid);
                $data = db_query_hash('help_type', $param);
                break;


            default:
                return false;
                break;
        }


        return $data;
    }

}

?>
